﻿using System.Collections.Generic;
using Models;
using Providers;

namespace Services
{
    /// <summary>
    /// Manage lists of saved databases
    /// </summary>
    public class SavedDatabasesService
        : ServiceBase<ISavedDatabasesProvider>
    {
        /// <summary>
        /// Initialise the SavedDatabases service
        /// </summary>
        public SavedDatabasesService()
        {
            Initialise();
        }

        /// <summary>
        /// Save a list of databases for later use
        /// </summary>
        /// <param name="listName">The name of the database list to save</param>
        /// <param name="databases">The list of databases to save</param>
        /// <param name="errorMsg">Any error message generated when trying to save the list</param>
        /// <returns>True if the list was saved</returns>
        public bool SaveList(string listName, List<Database> databases, out string errorMsg)
        {
            return Provider.SaveList(listName, databases, out errorMsg);
        }

        /// <summary>
        /// Load a list of databases
        /// </summary>
        /// <param name="listName">The name of the database list to load</param>
        /// <param name="errorMsg">Any error message generated when trying to load the list</param>
        /// <returns>A list of databases</returns>
        public List<Database> LoadList(string listName, out string errorMsg)
        {
            return Provider.LoadList(listName, out errorMsg);
        }

        /// <summary>s
        /// Create a provider of the type used by the service
        /// </summary>
        /// <returns>A provider</returns>
        protected override ISavedDatabasesProvider CreateProvider()
        {
            return ProviderFactory.CreateSavedDatabasesProvider();
        }
    }
}
